<template>
  <el-form :label-position="labelPosition" label-width="80px" :model="formInline" :rules="rules" ref="ruleForm1">
    <el-form-item label="商品名称" prop="gname"  >
      <el-input v-model="formInline.gname" ></el-input>
    </el-form-item>
    <el-form-item label="仓库名称" prop="sName" >
      <el-input v-model="formInline.sName" ></el-input>
    </el-form-item>
    <el-form-item label="数量" prop="number"  >
      <el-input v-model="formInline.number" @blur="checks"></el-input>
    </el-form-item>
    <el-form-item label="单价" prop="price" >
      <el-input v-model="formInline.price" @blur="checks"></el-input>
    </el-form-item>
    <el-form-item label="总金额" >
      <el-input v-model="formInline.sumPrice" disabled placeholder="自动计算"> </el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="onSubmit('ruleForm1')">确认入库</el-button>
      <el-button @click="resetForm('ruleForm')">重置</el-button>
      <el-button @click="black">返回</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
export default {
  name: "Put",
  data() {
    return {
      labelPosition: 'right',
      formInline: {
        gname: '',
        sName: '',
        price:'',
        sumPrice:'',
        number:'',

      },
      rules:{
        gname :[{required: true, message: '请输入', trigger: 'blur'}],
        sName :[{required: true, message: '请输入', trigger: 'blur'}],
        price :[{required: true, message: '请输入', trigger: 'blur'}],
        number :[{required: true, message: '请输入', trigger: 'blur'}]
      }
    };
  },
  methods:{
    checks(){
      //if(this.formIn.number!=null||this.formIn.number!='')
      this.formInline.sumPrice=this.formInline.number*this.formInline.price;
    },
    onSubmit(formName){
      this.$refs[formName].validate((valid) => {
        if (valid) {
          var vm = this
          this.axios({
            method:"POST",
            url:"/api/inventory/insert",
            data:{
              gname:vm.formInline.gname,
              sName:vm.formInline.sName,
              price:vm.formInline.price,
              sumPrice:vm.formInline.sumPrice,
              number:vm.formInline.number
            }
          }).then(function (res){
            if(res.data.code == 200){
              vm.$message(res.data.msg)
            }else{
              vm.$message(res.data.msg)
            }
          })
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    black(){
      this.$router.push('/inventory/List')
    }
  }
}
</script>

<style scoped>

</style>
